package com.wuxx.quartz.entity;
import org.nutz.dao.entity.annotation.Column;
import org.nutz.dao.entity.annotation.Comment;
import org.nutz.dao.entity.annotation.EL;
import org.nutz.dao.entity.annotation.Name;
import org.nutz.dao.entity.annotation.Prev;
import org.nutz.dao.entity.annotation.Table;
import org.nutz.lang.Strings;
import org.quartz.JobKey;

import java.util.Date;
import java.util.UUID;

/**
 * 任务信息表
 * @author wuxx
 * @date 2023-05-06 10:30
 */
@Table("S_TASK_INFO")
public class STaskInfo {

    /**
     * 任务主键ID TAKE_ID
     */
    @Name
    @Prev(els = @EL("$me.initUUID()"))
    @Column("TASK_ID")
    @Comment("任务主键ID")
    private String taskId;
    /**
     * 任务英文名称 TASK_CH_NAME
     */
    @Column("TASK_CH_NAME")
    @Comment("任务中文名称")
    private String taskChName;
    /**
     * 任务英文名称 TASK_EN_NAME
     */
    @Column("TASK_EN_NAME")
    @Comment("任务英文名称")
    private String taskEnName;
    /**
     * 任务分组 TASK_GROUP
     */
    @Column("TASK_GROUP")
    @Comment("任务分组")
    private String taskGroup;
    /**
     * 任务描述 TASK_DESCRIPTION;
     */
    @Column("TASK_DESCRIPTION")
    @Comment("任务描述")
    private String taskDescription;
    /**
     * 任务CRON TASK_CRON;
     */
    @Column("TASK_CRON")
    @Comment("任务CRON")
    private String taskCron;
    /**
     * 任务类 TASK_CLASS;
     */
    @Column("TASK_CLASS")
    @Comment("任务类")
    private String taskClass;

    /**
     * 任务类型 TASK_TYPE;
     * CRON("标准CRON支持"),
     * INTERVAL_MILLISECOND("固定间隔毫秒"),
     * INTERVAL_SECOND("固定间隔秒"),
     * INTERVAL_MINUTE("固定间隔分钟"),
     * INTERVAL_HOUR("固定间隔小时")
     *
     */
    @Column("TASK_TYPE")
    @Comment("任务类型")
    private String taskType;
    /**
     * 任务执行时间 TASK_EXECUTION_TIME;
     */
    @Column("TASK_EXECUTION_TIME")
    @Comment("任务执行时间")
    private Date taskExecutionTime;
    /**
     * 状态（1运行中、2暂停、0停止） STATUS;
     * map.put("5", "阻塞");
     * map.put("4", "完成");
     * map.put("3", "出错");
     * map.put("-1", "不存在");
     * map.put("1", "正常");
     * map.put("2", "暂停");
     * map.put("0", "停止");
     */
    @Column("STATUS")
    @Comment("状态")
    private String status;
    /**
     *创建时间 CREATE_TIME;
     */
    @Column("CREATE_TIME")
    @Comment("创建时间")
    private Date createTime;
    /**
     *更新时间 UPDATE_TIME;
     */
    @Column("UPDATE_TIME")
    @Comment("更新时间")
    private Date updateTime;
    /**
     *间隔单位 TASK_INTERVAL_UNIT
     * INTERVAL_MILLISECOND("固定间隔毫秒"),
     * INTERVAL_SECOND("固定间隔秒"),
     * INTERVAL_MINUTE("固定间隔分钟"),
     * INTERVAL_HOUR("固定间隔小时")
     */
    @Column("TASK_INTERVAL_UNIT")
    @Comment("间隔单位")
    private String taskIntervalUnit;
    /**
     *间隔时间 TASK_INTERVAL
     */
    @Column("TASK_INTERVAL")
    @Comment("间隔时间")
    private Long taskInterval;
    /**
     *重复次数 TASK_REPEAT;
     */
    @Column("TASK_REPEAT")
    @Comment("重复次数")
    private int taskRepeat;


    /**
     *是否删除 DEL_FLAG;
     */
    @Column("DEL_FLAG")
    @Comment("是否删除")
    private Boolean delFlag;


    public String initUUID() {
        if (Strings.isEmpty(taskId)){
            return UUID.randomUUID().toString().replaceAll("-", "");
        }
        return this.taskId;
    }

    public STaskInfo() {
    }

    public String getTaskId() {
        return taskId;
    }

    public void setTaskId(String taskId) {
        this.taskId = taskId;
    }

    public String getTaskEnName() {
        return taskEnName;
    }

    public void setTaskEnName(String taskEnName) {
        this.taskEnName = taskEnName;
    }

    public String getTaskGroup() {
        return taskGroup;
    }

    public void setTaskGroup(String taskGroup) {
        this.taskGroup = taskGroup;
    }

    public String getTaskDescription() {
        return taskDescription;
    }

    public void setTaskDescription(String taskDescription) {
        this.taskDescription = taskDescription;
    }

    public String getTaskCron() {
        return taskCron;
    }

    public void setTaskCron(String taskCron) {
        this.taskCron = taskCron;
    }

    public String getTaskClass() {
        return taskClass;
    }

    public void setTaskClass(String taskClass) {
        this.taskClass = taskClass;
    }

    public String getTaskType() {
        return taskType;
    }

    public void setTaskType(String taskType) {
        this.taskType = taskType;
    }

    public Date getTaskExecutionTime() {
        return taskExecutionTime;
    }

    public void setTaskExecutionTime(Date taskExecutionTime) {
        this.taskExecutionTime = taskExecutionTime;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Date getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }

    public Boolean getDelFlag() {
        return delFlag;
    }

    public void setDelFlag(Boolean delFlag) {
        this.delFlag = delFlag;
    }


    public JobKey getJobKey() {
        return JobKey.jobKey(this.taskEnName, this.getTaskGroup());
    }

    public String getTaskIntervalUnit() {
        return taskIntervalUnit;
    }

    public void setTaskIntervalUnit(String taskIntervalUnit) {
        this.taskIntervalUnit = taskIntervalUnit;
    }

    public Long getTaskInterval() {
        return taskInterval;
    }

    public void setTaskInterval(Long taskInterval) {
        this.taskInterval = taskInterval;
    }

    public int getTaskRepeat() {
        return taskRepeat;
    }

    public void setTaskRepeat(int taskRepeat) {
        this.taskRepeat = taskRepeat;
    }
}

